/**
  ******************************************************************************
  * @file    app_hci.h
  * @author  Feirui_Joe
  * @version V0.1
  * @date    07/26/2010
  * @brief   Display interface
  ******************************************************************************
  * @copy
  *
  * <h2><center>&copy; COPYRIGHT 2010 Feirui</center></h2>
  */ 



/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef  __APP_HCI_H__
#define  __APP_HCI_H__


#ifdef __cplusplus
 extern "C" {
#endif


/**
  * @brief GLOBALS RAM definition
  */
#ifdef   APP_GLOBALS_HCI
#define  APP_EXT_HCI
#else
#define  APP_EXT_HCI  extern
#endif


/* StateUpdIn OS_Flags config bits */
#define OSHCIFlags_LEDRequest                     ((OS_FLAGS)DEF_BIT_00)
#define OSHCIFlags_LEDTiming1                     ((OS_FLAGS)DEF_BIT_01)
#define OSHCIFlags_LCDRequest                     ((OS_FLAGS)DEF_BIT_02)
#define OSHCIFlags_LCDTiming                      ((OS_FLAGS)DEF_BIT_03)
#define OSHCIFlags_DstInButtonReq                 ((OS_FLAGS)DEF_BIT_04)
#define OSHCIFlags_ButtonTiming                   ((OS_FLAGS)DEF_BIT_05)
#define OSHCIFlags_CommButtonReq                  ((OS_FLAGS)DEF_BIT_06)
#define OSHCIFlags_SMSButtonReq                   ((OS_FLAGS)DEF_BIT_07)
#define OSHCIFlags_LEDTiming2                     ((OS_FLAGS)DEF_BIT_08)
#define OSHCIFlags_LEDTiming3                     ((OS_FLAGS)DEF_BIT_09)
#define OSHCIFlags_LCDReflash                     ((OS_FLAGS)DEF_BIT_10)
#define OSHCIFlags_Reserve11                      ((OS_FLAGS)DEF_BIT_11)
#define OSHCIFlags_Reserve12                      ((OS_FLAGS)DEF_BIT_12)
#define OSHCIFlags_Reserve13                      ((OS_FLAGS)DEF_BIT_13)
#define OSHCIFlags_Reserve14                      ((OS_FLAGS)DEF_BIT_14)
#define OSHCIFlags_Reserve15                      ((OS_FLAGS)DEF_BIT_15)

#define OSHCIFlags_TIMING                         (OSHCIFlags_LEDTiming1|\
                                                   OSHCIFlags_LEDTiming2|\
                                                   OSHCIFlags_LEDTiming3|\
                                                   OSHCIFlags_LCDTiming| \
                                                   OSHCIFlags_ButtonTiming)

#define OSHCIFlags_REQUEST                        (OSHCIFlags_LEDRequest    |\
                                                   OSHCIFlags_LCDRequest    |\
                                                   OSHCIFlags_DstInButtonReq|\
                                                   OSHCIFlags_CommButtonReq |\
                                                   OSHCIFlags_SMSButtonReq  |\
                                                   OSHCIFlags_LCDReflash) 

#define OSHCIFlags_ALL                            (OSHCIFlags_REQUEST|OSHCIFlags_TIMING)
#define OSHCIFlags_DefaultValue                   ((OS_FLAGS)    0x0000)


/* Result Request */
#define HCIOutRequestBit_NormalCfgUpd             DEF_BIT_00
#define HCIOutRequestBit_CalibCfgUpd              DEF_BIT_01
#define HCIOutRequestBit_ButtonUpd                DEF_BIT_02
#define HCIOutRequestBit_LCDCfgUpd                DEF_BIT_03
#define HCIOutRequestBit_AccumuCfgUpd             DEF_BIT_04

/* HCI action */
#define HCIActionBit_ButtonReq                    DEF_BIT_00
#define HCIActionBit_LCDReq                       DEF_BIT_01
#define HCIActionBit_LEDReq                       DEF_BIT_02
#define HCIActionBit_LVxINCAct1                   DEF_BIT_03
#define HCIActionBit_LVxDECAct1                   DEF_BIT_04
#define HCIActionBit_LVxINCAct2                   DEF_BIT_05
#define HCIActionBit_LVxDECAct2                   DEF_BIT_06

/* LCD Update */
#define HCIFullLCDUpdateTiLimit                   (HCILCDTimingFreq*8)
APP_EXT_HCI uint8_t HCILCDUpdateTiCnt;

#define LCDUpdateControl_FullMode      0
#define LCDUpdateControl_PartMode      1

#define HCIKeyScanTimingFreq                      20     /* 20HZ  */
#define HCIDataTimingFreq                         3      /*  3HZ  */
#define HCILCDTimingFreq                          10     /* 10HZ  */
#define HCILEDTimingFreq                          20     /* 20HZ  */

#define LEDShowPeriodVal_2tps                      (HCILEDTimingFreq/2)
#define LEDShowPeriodVal_5tps                      (HCILEDTimingFreq/5)
APP_EXT_HCI uint8_t AuxiLEDShowCount;

#define ReCfgLCDTiLimit                           (HCILCDTimingFreq*3)
APP_EXT_HCI uint8_t ReCfgLCDTiCnt;
#define RePORLCDSta_Null                          0
#define RePORLCDSta_Fault                         1
#define RePORLCDSta_Normal                        2
APP_EXT_HCI uint8_t RePORLCDTiSta;

/* EL */
#define ELTouchStaBitKey                          DEF_BIT_00
#define ELTouchStaBitWorkFlow                     DEF_BIT_01
APP_EXT_HCI uint8_t  ELTouchStatus;
APP_EXT_HCI uint32_t ELTouchKeyTiCnt;

/* Buzzer */
#define BuzzerMode_None                           0
#define BuzzerMode_KeyPress                       1
#define BuzzerMode_GensetFault                    2
#define BuzzerMode_GensetWarn                     3
#define BuzzerMode_GensetStart                    4
APP_EXT_HCI uint8_t  BuzzerModeCmd;
APP_EXT_HCI uint8_t  BuzzerModeSta;
APP_EXT_HCI uint8_t  BuzzerRepeatCnt;
APP_EXT_HCI uint8_t  BuzzerTiCnt;

APP_EXT_HCI uint8_t  BuzzerLastButtonSta;
#define ButtonBuzzerTiGap                         (HCIKeyScanTimingFreq/2)          /* 0.5s */
APP_EXT_HCI uint8_t  BuzzerLastButtonCnt;

/* Button */
#define NoButtonTiLimit_ExitCfg                   (HCIKeyScanTimingFreq*60*5)
APP_EXT_HCI uint16_t NoButtonExitCfgTiCnt;
#define NoButtonTiLimit_Scroll                    (HCIKeyScanTimingFreq*60*2)
APP_EXT_HCI uint16_t NoButtonLCDScrollTiCnt;

APP_EXT_HCI uint8_t  LCDScrollFlag;
APP_EXT_HCI uint16_t LCDScrollTiCnt;

/*---------------------------------------------------------Dynamic Password*/
#define ManualPSWVaildTiLimit                    (HCILCDTimingFreq    *10)              /* 10s */
#define DynimoPSWReqCodeTiLimit                  (HCIKeyScanTimingFreq*60*30)           /* 1800s */
APP_EXT_HCI uint16_t  DynimoPSWReqCodeTiCnt;

/* LED Test */
APP_EXT_HCI uint8_t  LEDTestActiveCnt;

/* Button Long Hold */
APP_EXT_HCI uint8_t  LongHoldLastButtonSta;
#define ButtonLongHoldActiveTiGap                      (HCIKeyScanTimingFreq*2)          /* 2.0s */
#define ButtonLongHoldInActiTiGap                      (HCIKeyScanTimingFreq/2)          /* 0.5s */
APP_EXT_HCI uint8_t  LongHoldButtonActiveCnt;
APP_EXT_HCI uint8_t  LongHoldButtonInActiCnt;

/* LED Timing */
APP_EXT_HCI uint8_t  LEDTimingCounter;

/* LCD Contrast Config Update */
#define LCDConfigUpdateTiLimit                          (HCIKeyScanTimingFreq*2)         /* 2s */
APP_EXT_HCI uint8_t  LCDCfgUpdateTiDelay;

APP_EXT_HCI int16_t  LCDContrastOldVal;

APP_EXT_HCI uint8_t  LCDMainPageShowSta;
#define LCDMainPageRestTime          (HCIKeyScanTimingFreq*30)
APP_EXT_HCI uint16_t LCDMainPageShowCnt;




APP_EXT_HCI uint8_t TransferLanguageCodeToOrder(uint16_t Code);
APP_EXT_HCI uint8_t CheckifUpdateLEDnBZWorkload(void);
APP_EXT_HCI void PORGlobalRAMReset_HCI(void);

#ifdef __cplusplus
}
#endif


#endif   /*  __APP_HCI_H__  */

/******************* (C) COPYRIGHT 2010 Feirui *****END OF FILE****/